﻿USE [QLLVANTAI]
GO

/****** Object:  StoredProcedure [dbo].[sp_XemLichVanChuyen_tatca]    Script Date: 09/27/2013 23:03:14 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO




CREATE proc [dbo].[sp_XemLichVanChuyen_tatca]
		@error nvarchar(100) out, @slxe int out

as

begin tran

	begin tran
	
	
	if exists (select * from LichVanChuyen LVC where LVC.Gio_Di > GETDATE())
	begin
		-- set sl xe
		 
		set @slxe = (select COUNT(*)
			from ChiTietLich CTL, LichVanChuyen LVC
			where CTL.Ma_VanChuyen = LVC.Ma_VanChuyen and LVC.Gio_Di > GETDATE())
		
		waitfor delay '00:00:10'			
		-- select data
		select LVC.Ma_VanChuyen, Diem_XuatPhat,Diem_Den ,CTL.Ma_Xe, Khoang_Cach,Gio_Di, Gio_Den , CTL.So_TaiXeTrong, CTL.So_PhuLaiTrong  
			from ChiTietLich CTL, LichVanChuyen LVC, TuyenDuong TD
			where CTL.Ma_VanChuyen = LVC.Ma_VanChuyen  and LVC.Ma_TuyenDuong = TD.Ma_TuyenDuong and LVC.Gio_Di > GETDATE()
			order by Diem_XuatPhat
			commit tran
	end
	
	else
	begin
		set @error = N'Lỗi: không tồn tại lịch đi nào'
		rollback
		--print @error 
		
	end
GO

